package cn.kgc.spring.factory;

import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author 课工场
 * @date 2024/11/5
 * @description  静态工厂的方式 实现复杂类型对象的获取
 */
public class ConnectionStaticFactory {

    public static Connection  createConnection(){

        String url = "jdbc:mysql:///java2426";
        String username = "root";
        String password = "root";
        try {
            Driver driver = new Driver();
            DriverManager.registerDriver(driver);
            return DriverManager.getConnection(url, username, password);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
